package com.learning.controller.teacher;


import com.learning.dto.QuestionDetailDTO;
import com.learning.dto.QuestionPageQueryDTO;
import com.learning.result.PageResult;
import com.learning.result.Result;
import com.learning.service.IQuestionService;
import com.learning.vo.QuestionDetailVO;
import com.learning.vo.QuestionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 题目表 前端控制器
 * </p>
 *
 * @author itRao
 * @since 2024-05-24
 */
@RestController
@RequestMapping("/teacher/question")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "题目相关接口")
public class QuestionController {
    //TODO 教师增删改题目

    private final IQuestionService questionService;

    /**
     * 分页查询题目
     *
     * @param dto
     * @return
     */
    @ApiOperation("分页查询题目")
    @GetMapping("/page")
    public Result<PageResult<QuestionVO>> pageQuery(QuestionPageQueryDTO dto) {
        log.info("请求参数：{}", dto);
        PageResult<QuestionVO> vo = questionService.pageQuery(dto);
        return Result.success(vo);
    }

    /**
     * 根据问题ID查询问题细节
     *
     * @param id
     * @return
     */
    @ApiOperation("根据问题ID查询问题细节")
    @GetMapping("/{id}")
    public Result<QuestionDetailVO> queryDetail(@PathVariable("id") Long id) {
        QuestionDetailVO vo = questionService.queryDetail(id);
        return Result.success(vo);
    }

    /**
     * 新增问题
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增问题")
    @PostMapping
    public Result<String> saveQuestion(@RequestBody QuestionDetailDTO dto) {
        questionService.saveQuestion(dto);
        return Result.success();
    }

    /**
     * 根据问题id修改问题详细
     *
     * @param dto
     * @return
     */
    @ApiOperation("根据问题id修改问题详细")
    @PutMapping
    public Result<String> updateQuestion(@RequestBody QuestionDetailDTO dto) {
        questionService.updateQuestion(dto);
        return Result.success();
    }

    /**
     * 根据问题ID删除问题
     *
     * @param id
     * @return
     */
    @ApiOperation("根据问题ID删除问题")
    @DeleteMapping
    public Result<String> deleteQuestion(Long id) {
        questionService.deleteQuestion(id);
        return Result.success();
    }
}
